<?php	
    include_once(dirname(__FILE__). "/../../../managers/class.User_Manager.php");
    include_once(dirname(__FILE__). "/../../../managers/class.Order_Manager.php");
    include_once(dirname(__FILE__). "/../../../managers/class.Parameters_Manager.php");
    include_once(dirname(__FILE__). "/../../../treatments/class.Log.php");

    class OrderAdministration_Presenter{

        private $user_manager;
        private $order_manager;
        private $param_manager;
        
        private $order_administrators;

        public function __construct($userId){
            //--initialisation des attibuts
            $this->user_manager = new User_Manager($userId, "../../");
            $this->order_manager = new Order_Manager($userId, "../../");
            $this->param_manager = new Parameters_Manager();
            
            $this->order_administrators = array(array());

            Log::ajoutLignePage($userId, "Administration: Orders", "../../");
        }
        
        public function getUserPictureDirectory(){
            return $this->param_manager->getUserPictureDirectory();
        }
        
        public function getOrderPictureDirectory(){
            return $this->param_manager->getOrderPicturesDirectory();
        }
        
        public function getAllOrder(){
            $orders = $this->order_manager->getAllOrders();
            //--Pour chaque ordre
            foreach($orders as $order){
                //--Pour chaque id administrateurs
                foreach($order->getIdAdministrateurs() as $adminid){
                    $this->order_administrators[$order->getId()][] = $this->user_manager->getUserById($adminid);
                }
            }
            return $orders;
        }
        
        public function getAdminToOrder($orderId){
            return $this->order_administrators[$orderId];
        }
        
        public function getAllUsers(){
            return $this->user_manager->getAllUser(true);
        }
        
        public function upgradeAdministrator($userId, $orderId){
            return $this->order_manager->setAdminToOrder($userId, $orderId);
        }
        
        public function downgradeAdministrator($userId, $orderId){
            return $this->order_manager->unSetAdminToOrder($userId, $orderId);
        }
    }